package com.huifer.wgx.json;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.vividsolutions.jts.geom.Geometry;
import java.io.IOException;

/**
 * @author huifer
 */
public class GeometryJsonSerializer extends JsonSerializer<Geometry> {
    @Override
    public void serialize(Geometry geometry, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        String jsonValue = "null";
        try {
            if (geometry != null) {
                jsonValue = geometry.toString();
            }
        } catch (Exception e) {
            // 不处理
        }
        jsonGenerator.writeString(jsonValue);
    }
}
